//
//  ZZP_BaseModel.m
//  A段_旅游_兜兜风
//
//  Created by dllo on 15/9/9.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "ZZP_BaseModel.h"

@implementation ZZP_BaseModel


// KVC 的纠错方法
- (id)valueForUndefinedKey:(NSString *)key
{
    return nil;
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{

}
- (instancetype)initWithDictionary:(NSDictionary *)dictionary
{
    self = [super init];
    if (self) {
        // KVC赋值
        [self setValuesForKeysWithDictionary:dictionary];
    }
    return self;
}

// 遍历构造器
+ (instancetype)baseModelWithDictionary:(NSDictionary *)dictionary
{
    // 利用多态封装初始化方法  [self class]多态
    id object = [[[self class] alloc] initWithDictionary:dictionary] ;
    return object;
}

// 转化方法
+ (NSMutableArray *)baseModelArrayWithArray:(NSArray *)array
{
    // 创建一个可变数组 保存model  并反返回结果
    NSMutableArray *resultArray = [NSMutableArray array];
    // 遍历参数数组
    for (NSDictionary *dictionary in array) {
        @autoreleasepool {
            // 创建对象
            id model = [[self class] baseModelWithDictionary:dictionary];
            // 添加到数组中
            [resultArray addObject:model];
        }
    }
    return resultArray;
}


@end
